package reflect;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;

/**
 * 通过反射类对象来实例化对象、两种方式
 * 一个直接用类对象的newinstance方法调用无参构造创建对象，
 * 第二个是用类对象的getConstructor方法获取反射类对象的构造器对象，构造器
 */

public class Test {
    public static void main(String[] args){
        try {
            Class cls = Class.forName("reflect.Student");
            Object o = cls.newInstance();
            Constructor constructor = cls.getConstructor(String.class,int.class,String.class);
            Object o2 = constructor.newInstance("张三",23,"男");

        } catch (NoSuchMethodException e) {
            throw new RuntimeException(e);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
}
